/**
 * 
 */
var winErreur=null;

/**
 * 
 */
var aideContextuel = '<i>Selectionner un sous menu</i>';

/**
 *
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE
 */
var tpl = new Ext.Template(
		'<b>Menu selectionne:<br/></b>{text}<br/><br/><b>Description:</b><br/>{aideContextuelle}'
	);
tpl.compile();


/**
 * 
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE
 */
var detailsPanel = {
					xtype:'panel', 
					id: 'details-panel',
					 title: 'Aide contextuelle',
					 region: 'center',
					 bodyStyle: 'padding-bottom:15px;',
					 autoScroll: true,
					 html: aideContextuel
		 			};

/**
 *
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE 
 */
var treePanel = new Ext.tree.TreePanel({
				 id: 'tree-menu-panel',
				 title:'',
				 region:'north',
				 split: true,
				 height: 200,
				 minSize: 150,
				 autoScroll: true,
				 rootVisible: false,
				 lines: false,
				 singleExpand: true,
				 useArrows: false,
				 loader: new Ext.tree.TreeLoader({ dataUrl:urlMenu }),
				 root: new Ext.tree.AsyncTreeNode()
	}
);

		 

/**
 * 
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE 
 */
treePanel.on('click', function(n) {
        		//Assign the changeLayout function to be called on tree node click.
				commonEffacerZoneMessages();
				var elAideContextuel = Ext.getCmp('details-panel').body;
			    if(!Ext.getCmp('panelCentral')){
			    	commonPopupErreurFatal();
			   	}
			    Ext.getCmp('panelCentral').update('');
				if(n && n.leaf){
			        tpl.overwrite(elAideContextuel, n.attributes);
			        //si l'url est renseigner alors charger sinon considerer que le menu est inactif
			        if(!Ext.isEmpty(n.attributes.url)){
			        	var lIdCmp='formPrincipal';
        				var lIdContainer = 'panelCentral';
        				var lUrl=contextPath+n.attributes.url;
        				commonLoadUrlInComponent(lIdCmp,lIdContainer, lUrl);
			        }
			    }else{
			    	if(n){
			    		if(n.isExpanded()){
			    			n.collapse();
			    		}else{
			    			n.expand();
			    		}
			    	}
			    	elAideContextuel.update(aideContextuel);
			    }
				gerererFilAriane(n);	
});


/**
 * 
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE
 * @param noeudArbre
 * @return
 */
var gerererFilAriane=function(noeudArbre){
	var pile='';
	while (noeudArbre && !noeudArbre.isRoot) {
		if(pile){
				pile =  noeudArbre.attributes.text+' > '+pile ;
		}
		else { 
				pile =  noeudArbre.attributes.text;
		}
		noeudArbre = noeudArbre.parentNode;
	}
	
	tableauAriane = Ext.get('ariane').dom.innerText.split(">");
	if(tableauAriane[1])
	  pile=tableauAriane[1]+' > '+pile;
	
	pile=' > '+pile;
	
	tplFileAriane.overwrite(Ext.get('ariane'), {pile:pile});
}


/**
 * 
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE 
 */		 
Ext.ns('customViewport');


/**
 *
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE
 */
Ext.override(Ext.Viewport, {
    initComponent : function() {
        Ext.Viewport.superclass.initComponent.call(this);
        this.el = Ext.get(this.el) || Ext.getBody();
        if (this.el.dom === document.body) {
	        this.el.dom.parentNode.className += ' x-viewport';
        }
        this.el.setHeight = Ext.emptyFn;
        this.el.setWidth = Ext.emptyFn;
        this.el.setSize = Ext.emptyFn;
        this.el.dom.scroll = 'no';
        this.allowDomMove = false;
        this.autoWidth = true;
        this.autoHeight = true;
        Ext.EventManager.onWindowResize(this.fireResize, this);
        this.renderTo = this.el;
    }
});
		
		
/**
 * 
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE
 */
customViewport = function() {
	// create application
	// private space

	return {
 
		// public methods
		init: function() {

		new Ext.Viewport({
			layout:		'border',
			id:			'theView',
			el:			'mvp',
			style: Ext.isIE ? 'height:100%;width:100%;' : 'height:95%;width:100%;',
			defaults:	{
				height:			100,
				width:			100,
				collapsible:	true,
				collapseMode:	'mini',
				split:			true
			},
			items:	[
				{
					xtype:			'container',
					autoEl:			{},
					layout:			'fit',
					region:			'center',
					collapsible:	false,
					border:false,
					id:				'centerRegion',
					items:	[{xtype:'panel',
						      autoScroll:true,
						      id:'panelCentral',
						      title:titreDuPanel
						      }]
				},
				{
					
					region:			'north',
					id:'zoneMessages',
					split:			false,
					collapsible:	false,
					height:		20,
					border:false,
					html:'<div class="agaucheMessErr">&nbsp;</div><div class="messErrVide">&nbsp;</div>'
				},
				{
					 layout: 'border',
					 id: 'layout-browser',
					 title: titreDuActionsPanel,
					 region:'west',
					 border: false,
					 split:true,
					 width: 188,
					 minSize: 100,
					 maxSize: 500,
					 items: [treePanel, detailsPanel]
				}
			]
		});
		    
 		}
	};
 }(); // end of app

 
 /**
  * 
  */
Ext.onReady(customViewport.init, customViewport);
		

		    
		

				
				